﻿using System.Linq;
using Garfield.Core.Runtime;
using PicoContainer.Defaults;

namespace Garfield.Runtime.Pico
{
    class ServiceLocator : IServiceLocator
    {
        private readonly DefaultPicoContainer context;

        public ServiceLocator(DefaultPicoContainer context)
        {
            this.context = context;
        }

        public Api GetService<Api>()
        {
            return (Api)context.GetComponentInstance(typeof(Api));
        }

        public Api[] GetServices<Api>()
        {
            return context.GetComponentInstancesOfType(typeof(Api)).Cast<Api>().ToArray();
        }
    }
}
